<?php
/*
$path = get_include_path() ;
echo $path;
set_include_path($path);
*/

include_once($_SERVER["DOCUMENT_ROOT"]."/bolsa_trabajo/email/class.phpmailer.php");
include_once($_SERVER["DOCUMENT_ROOT"]."/bolsa_trabajo/email/globalUtilitiesParameters.php");
include_once($_SERVER["DOCUMENT_ROOT"]."/bolsa_trabajo/email/email_distribution_list.php");
/*
$admonEmail = EmailDistributionList:: getEmailAdministradores();
sentEmail('Esto es una prueba','Esto es una prueba',$admonEmail);
*/
function sentEmail($greeting, $message, $subject,$toAddressesArray){

	global $hostSMTP ;
	global $fromEmail;
	global $fromName;
	global $portSMTP;
	global $usernameSMTP;
	global $passwordSMTP;
	global $senderEmailSMTP;
	global $senderNameSMTP ;
	$mail = new PHPMailer();
	//Tell PHPMailer to use SMTP
	$mail->IsSMTP();
	//Enable SMTP debugging
	// 0 = off (for production use)
	// 1 = client messages
	// 2 = client and server messages
	$mail->SMTPDebug  = 2;
	//Ask for HTML-friendly debug output
	$mail->Debugoutput = 'html';
	//Set the hostname of the mail server
	$mail->Host       = $hostSMTP;
	//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
	$mail->Port       = $portSMTP;
	//Set the encryption system to use - ssl (deprecated) or tls
	$mail->SMTPSecure = 'tls';
	//Whether to use SMTP authentication
	$mail->SMTPAuth   = true;
	//Username to use for SMTP authentication - use full email address for gmail
	$mail->Username   = $usernameSMTP;
	//Password to use for SMTP authentication
	$mail->Password   = $passwordSMTP;
	//Set who the message is to be sent from
	$mail->SetFrom($fromEmail, $fromName);
	//Set an alternative reply-to address
	$mail->AddReplyTo($fromEmail, $fromName);
	//Set who the message is to be sent to
	foreach ($toAddressesArray as $emailAddress){
		$mail->AddAddress($emailAddress);
	}
	//Set the subject line
	$mail->Subject =   $subject   ;

	$mail->Body = $greeting . $message;
	//Replace the plain text body with one created manually
	$mail->AltBody = $greeting. $message;
	//Attach an image file


	//Send the message, check for errors
	if(!$mail->Send()) {
	  return true;
	} else {

		return true;
	  //echo "Message sent :)!";
	}



}



?>